type First<T extends any[]> = T extends [infer F, ...any[]] ? F : []
type Last<T extends any[]> = T extends [...any[], infer L] ? L : []

type DeleteFirst<T extends any[]> = T extends [unknown, ...infer Rest] ? Rest : []
type DeleteLast<T extends any[]> = T extends [...infer Rest, unknown] ? Rest : []

type arr = [1, 2, 3]
type N1 = First<arr> // type N1 = 1
type N2 = Last<arr> // type N2 = 3
type N3 = DeleteFirst<arr> // type N3 = [2, 3]
type N4 = DeleteLast<arr> // type N4 = [1, 2]

// 如果是数组，则返回数组元素的类型
type Infer1<T> = T extends Array<any> ? T[number] : T
type N5 = Infer1<(boolean | string)[]> // boolean | string
type N6 = Infer1<string[]> // string
type N7 = Infer1<null> // null

type Infer2<T> = T extends Array<infer U> ? U : T
type N8 = Infer1<(boolean | string)[]> // boolean | string
type N9 = Infer1<string[]> // string
type N10 = Infer1<null> // null

// 转换元组
type TupleToUnionType<T> = T extends Array<infer R> ? R : never
type Tuple = [string | number, boolean]
type N11 = TupleToUnionType<Tuple> // string , number, boolean

type ReverseArrType<T extends any[]> = T extends [infer F, ...infer R] ? [...ReverseArrType<R>, F] : T
type Arr = [1, 2, 3]
// [3, 2, 1]
type N12 = ReverseArrType<Arr>
